<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>v-for指令</title>
</head>
<body>
    <!-- 2.挂载的html结构 -->
    <div id="app">
        <!--增加绑定-->
        <input type="button" value="添加数据" @click="add">
        <input type="button" value="移除数据" @click="remove">
        <ul>
            <li v-for="item in arr">回忆的地方：{{ item }}</li>
            <!--item名可替换任意-->
            <li v-for="it in arr">回忆的地方：{{ it }}</li>
            <!--添加索引页-->
            <li v-for="(item,index) in arr">{{ index+1 }} 回忆的地方：{{ item }}</li>
        </ul>
        <!--测试对象数组-->
        <h2 v-for="item in vegetables">{{ item }}</h2>
        <h2 v-for="item in vegetables">{{ item.name }}</h2>
        <h2 v-for="item in vegetables" :title="item.date">{{ item.date }}</h2>

    </div>
    <!-- 1.开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        //  3.创建Vue实例
        var app = new Vue({
            el:"#app",//el:挂载点 id选择器
            data:{
                arr:["NanJing","ShangHai","JiangXi"],
                //对象数组数据
                vegetables:[
                    {name:"西兰花"},
                    {name:"西红柿"},
                    {date:"2020-03-26"}

                ]
            },
            //操作数据变更
            methods:{
                add:function () {
                    this.vegetables.push({name:"花菜炒蛋"})
                },
                remove:function () {
                    this.vegetables.shift();//移除最左边元素
                }
            }
        })
    </script>
</body>
</html>
